<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
 
    <base href="<%=basePath%>">
    
    <title>My JSP 'editUser.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
body{
font-size:12px;
}
div{
	width:500px;
	height:500px;
	
}
table{
	margin-left:50px;
	font-size:13px;
}
select{
width:156px;
}
.bt{
width:80px;
margin-top:30px;
}
#btn{
margin-left:90px;
}
#btn1{
margin-left:30px;
}
td{
height:45px;
text-align:right;
}
</style>
  </head>
   
  <body>
  <div>
 <form action="jsp/user/update_list">
<table>
<tr>
<td>二级管理员账号：</td>
<c:if test="${sessionScope.level=='1'}">
<td><input type="text" value="${requestScope.username }" id="name" name="username"></td>
</c:if>
<c:if test="${sessionScope.level=='2'}">
<td><input type="text" value="${sessionScope.username }" id="name" name="username" readonly></td>
</c:if>
<td id="show"></td>
</tr>

<tr>
<td>管理员旧密码：</td>
<td><input type="password" id="psd" ></td>
<td id="showpsd"></td>
</tr>
<tr>
<td>管理员新密码：</td>
<td><input type="password" id="psd1"></td>
<td></td>
</tr>
<tr>
<td>重新输入新密码：</td>
<td><input type="password" id="psd2" name="password"></td>
<td id="show2"></td>
</tr>

<tr>
<td>电子邮件：</td>
<td><input type="text" name="email"></td>
<td></td>
</tr>
<tr>
<td>账号状态：</td>
<td><select name="state">
<option>正常</option>
<option>停用</option>
</select></td>
<td></td>
</tr>
</table>
<input type="submit" value="提交" class="bt" id="btn"/><input type="button" id="btn1"value="重置" class="bt" onclick="res()"/>
</form>
</div>
  </body>
  <script type="text/javascript" src="js/jquery-1.7.2.js"></script>
  <script type="text/javascript">

  $(document).ready(function(){
if($("#name").val()){
	$('#show').text("账号存在").css("color","green");
}
   $("#btn").attr("disabled", true);
  $("#name").blur(function(){
  
  $('#showpsd').text("");
    $('#psd').val("");
  var obj={};
  	obj.username=$(this).val();
  	if($(this).val()==""||$.trim($(this).val()).length==0){
  	
  	$('#show').text("请输入账号").css("color","red");
  		  $("#btn").attr("disabled", true);
  		
  	}else{
  		$.post('<%= basePath%>jsp/user/yz_list',obj,cl,'json');
  	}
  
  });
  
    $("#psd").blur(function(){
  var obj={};
  	obj.username=$("#name").val();
  	obj.userpsd=$(this).val();
  	if($(this).val()==""||$.trim($(this).val()).length==0){
  	
  	$('#showpsd').text("请输入密码").css("color","red");
  		  $("#btn").attr("disabled", true);
  		
  	}else{
  		$.post('<%= basePath%>jsp/user/yzpsd_list',obj,psd,'json');
  	}
  
  });
  
    $("#psd2").blur(function(){
    if($('#psd1').val()==""||$('#psd2').val()==""||$.trim($(this).val()).length==0||$.trim($('#psd1').val()).length==0){
   
     $('#show2').text("请输入密码").css("color","red");
       $("#btn").attr("disabled", true);
    }
   	else if($('#psd1').val()==$('#psd2').val()){
    $('#show2').text("两次密码相同").css("color","green");
    if($('#show').text()=="账号存在"&&$('#showpsd').text()=="密码正确"){
    $("#btn").attr("disabled", false);
    }
    }	
    else{
    $('#show2').text("两次密码不相同").css("color","red");
    $("#btn").attr("disabled", true);
    }
    });
    
  
  });
  
  
  function cl(data){
  	if(data.state=="0"){
  	$('#show').text("账号存在").css("color","green");
  		  if($('#show2').text()=="两次密码相同"&&$('#showpsd').text()=="密码正确"){
   
    	$("#btn").attr("disabled", false);
    
    }
  	}else{
  	$('#show').text("账号不存在").css("color","red");
  		  $("#btn").attr("disabled", true);
  		}
  		
  	}
  	
  	  function psd(data){
  	if(data.state=="0"){
  	$('#showpsd').text("密码正确").css("color","green");
  		  if($('#show2').text()=="两次密码相同"&&$('#show').text()=="账号存在"){
  		  
   
    	$("#btn").attr("disabled", false);
    	
    }
  	}else{
  	$('#showpsd').text("密码不正确").css("color","red");
  		  $("#btn").attr("disabled", true);
  		}
  		
  	}
  	function res(){
  	$("#btn").attr("disabled", true);
$('table input').val("");
	$('#show').text("");
	$('#show2').text("");
		$('#showpsd').text("");
  	}

  </script>
</html>
